import QtQuick 2.7
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3

ApplicationWindow {
    id: appwin
    objectName:"rooter"
    visible: true
    width: 400
    height: 300
    title: qsTr("Qml日历")

    function dayValid(date){
        var myArray = new Array();
        myArray[0]="13";
        myArray[1]="17";
        myArray[2]="26";

        for(var i = 0; i < myArray.length;i++)
        {
            if (myArray[i] === date)
            {
                return(false);
            }
        }
        return(true);
    }

    Calendar {
        anchors.centerIn: parent
        id: cals // 声明属性：<name>:  <value>
        width: 90; height: 90
        style: CalendarStyle {
            gridVisible: false
            dayDelegate: Rectangle {
                property bool dayIsValid: dayValid(styleData.date.getDate().toString())

                gradient: Gradient {
                    GradientStop {
                        position: 0.00
                        color: styleData.selected && dayIsValid ? "#148014" : (styleData.visibleMonth && styleData.valid ? (dayIsValid ? "#CCCCCC" : "#FFFFFF") : "#FFFFFF");
                    }
                }

                Label {
                    text: styleData.date.getDate()
                    anchors.centerIn: parent
                }

                Rectangle {
                    width: parent.width
                    height: 1
                    color: "#EEEEEE"
                    anchors.bottom: parent.bottom
                }

                Rectangle {
                    width: 1
                    height: parent.height
                    color: "#EEEEEE"
                    anchors.right: parent.right
                }
            }
        }
    }



    Text {
        objectName:"info"
        id: info3
        x: 20
        y: 20
        z: 1
        width: 700
        height: 130

       color: "green"
       font.pixelSize: 50
       font.family: "WenQuanYi Micro Hei"
       font.bold: true
       // 自定义属性，表示空格按下的次数
         property int spacePresses: 0
       text: "Space pressed: " + spacePresses + " times"
       // (1) 文本变化的响应函数，使用控制台输出信息
       onTextChanged: console.log("text changed to:", text)
       // 接收键盘事件，需要设置 focus 属性
       focus: true
       // (2) 调用 JavaScript 函数
       Keys.onSpacePressed: {
           increment()
       }
       // 按下 Esc 键清空文本
       Keys.onEscapePressed: {
           label.text = 'clear the text'
       }
       // (3) 一个 JavaScript 函数
       function increment() {
           spacePresses = spacePresses + 1
       }
    }




    Text {
          objectName:"info"
          id: info1
          x: 20
          y: 20
          z: 1
          width: 700
          height: 130

         color: "green"
         font.pixelSize: 50
         font.family: "WenQuanYi Micro Hei"
         font.bold: true
         // 自定义属性，表示空格按下的次数
           property int spacePresses: 0
         text: "Space pressed: " + spacePresses + " times"
         // (1) 文本变化的响应函数，使用控制台输出信息
         onTextChanged: console.log("text changed to:", text)
         // 接收键盘事件，需要设置 focus 属性
         focus: true
         // (2) 调用 JavaScript 函数
         Keys.onSpacePressed: {
             increment()
         }
         // 按下 Esc 键清空文本
         Keys.onEscapePressed: {
             label.text = 'clear the text'
         }
         // (3) 一个 JavaScript 函数
         function increment() {
             spacePresses = spacePresses + 1
         }
      }

     Text {
          objectName:"info2"
          id: info2
          x: 20
          y: 180
          z: 1
          width: 700
          height: 130
         text: "info2:"
         color: "green"
         font.pixelSize: 50
         font.family: "WenQuanYi Micro Hei"
         font.bold: true
      }
}



#include <QGuiApplication>
#include <QQmlApplicationEngine>


int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    engine.load(url);
    QObject *rooter =  engine.rootObjects().first();
    QString name  = rooter->objectName();
    QObject *label = rooter->findChild<QObject *>("info3");
    label->setProperty("text", "xxxxx");
    qDebug ("123");
  //  qDebug (rooter->children());

    return app.exec();
}



//------------------------------------->>>>>>>>>>>>>>>>>>>







